package cn.aitrox.ry.app.web.config;

import cn.aitrox.ry.app.web.interceptor.LoginInterceptor;
import cn.aitrox.ry.common.config.JsonMessageConverter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.converter.HttpMessageConverter;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport;

import java.util.List;

@Configuration
public class SpringMvcConfig extends WebMvcConfigurationSupport {

    @Autowired
    private LoginInterceptor loginInterceptor;

//    @Autowired
//    private AuthInterceptor authInterceptor;

    @Override
    public void extendMessageConverters(List<HttpMessageConverter<?>> converters) {
        converters.add(new JsonMessageConverter());
    }

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(loginInterceptor).order(0).addPathPatterns("/**").excludePathPatterns("/user/login", "/user/forget/pwd");
//        registry.addInterceptor(authInterceptor).order(1).addPathPatterns("/**").excludePathPatterns("/user/login", "/user/forget/pwd");
        super.addInterceptors(registry);
    }
}
